script_enemy_main{

let phase=0;

let move=0;
let movetime2=0;
let movespeed=0;
let type=0;

let positiontime=0;

let familiarangle=0;
if(GetArgument[0]<GetCenterX){ familiarangle=0; }
if(GetArgument[0]>GetCenterX){ familiarangle=180; }

let angle=0;
let radius=0;
let accel=0;
let speed=0;
let movetime1=60;

let usespell=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots5=("\script\SoundEffects\shots5.wav");
let SEshotm1=("\script\SoundEffects\shotm1.wav");
let SEshotm3=("\script\SoundEffects\shotm3.wav");
let SEshotb6=("\script\SoundEffects\shotb6.wav");
let SElaserm3=("\script\SoundEffects\laserm3.wav");

let GRfamiliar=("\script\Images\OtherEffects\SpellCircle1b.png");

@Initialize{
	LoadSE("\script\SoundEffects\shots5.wav");
	LoadSE("\script\SoundEffects\shotm1.wav");
	LoadSE("\script\SoundEffects\shotm3.wav");
	LoadSE("\script\SoundEffects\shotb6.wav");
	LoadSE("\script\SoundEffects\laserm3.wav");
	
	LoadGraphic("\script\Images\OtherEffects\SpellCircle1b.png");

	SetScore(1);
	SetLife(1);
	MagicCircle(false);
}
	
@MainLoop{

if(time==0){
let xpos=GetArgument[0];
let ypos=GetArgument[1];
	angle=atan2(ypos-GetY,xpos-GetX);
	radius=(((xpos-GetX)^2+(ypos-GetY)^2)^0.5)/movetime1*(pi/2);
}
if(time<movetime1){
	accel+=180/movetime1;
	speed=radius*sin(accel);
	SetX(GetX+speed*cos(angle));
	SetY(GetY+speed*sin(angle));
}
if(time==movetime1){ time=movetime1+floor(maxy-(GetY/8)); }

if(time%180==0 && time>=60){
	if(time%360==0 && GetX<cx){ movespeed=-1; }
	if(time%360==0 && GetX>cx){ movespeed=1; }
	if(time%360!=0 && GetX<cx){ movespeed=1; }
	if(time%360!=0 && GetX>cx){ movespeed=-1; }
move=1;
}

if(move==1){
	SetY(GetY+movespeed);
movetime2++;
}

if(movetime2==28){
	if(phase==0){
		if(type==0){
		let angle=0;
			loop(10){
			CreateShot01(GetX,GetY,1.25,angle,62,10);
			angle+=360/10;
			}
		if(GetX<cx){ PlaySE(SEshots5); }
		}
		if(type==1){
			if(GetX<cx){ CreateLaser01(GetX,GetY,3,0,200,20,58,10); }
			if(GetX>cx){ CreateLaser01(GetX,GetY,3,180,200,20,58,10); }
		if(GetX<cx){ PlaySE(SElaserm3); }
		}
		if(type==2){
			if(GetX<cx){ CreateShot01(GetX,GetY,1.5,0,123,10); }
			if(GetX>cx){ CreateShot01(GetX,GetY,1.5,180,123,10); }
		if(GetX<cx){ PlaySE(SEshotb6); }
		}
		if(type==3){
		let shot1=0;
		let delay=0;
		let angle=GetAngleToPlayer;
			loop(10){
			CreateShotA(shot1,GetX,GetY,10);
			SetShotDataA(shot1,0,3,angle,0,-0.1,0,44);
			SetShotDirectionType(PLAYER);
			SetShotDataA(shot1,40+delay,3,0,0,0,0,37);
			SetShotDirectionType(ABSOLUTE);
			FireShot(shot1);
			delay+=2;
			angle+=360/10;
			}
		if(GetX<cx){ PlaySE(SEshotm1); }
		}
		if(type==4){
		let speed=5;
		let color=1;
			loop(7){
			if(GetX<cx){ CreateShot01(GetX,GetY,speed,0,144+color,10); }
			if(GetX>cx){ CreateShot01(GetX,GetY,speed,180,144+color,10); }
			speed-=0.5;
			color++;
			}
		if(GetX<cx){ PlaySE(SEshotm3); }
		}
	}

	if(phase==1){
		if(type==0){
		let angle=0;
			loop(18){
			CreateShot01(GetX,GetY,1.25,angle,62,10);
			angle+=360/18;
			}
		if(GetX<cx){ PlaySE(SEshots5); }
		}
		if(type==1){
			if(GetX<cx){ CreateLaser01(GetX,GetY,3,0,400,20,58,10); }
			if(GetX>cx){ CreateLaser01(GetX,GetY,3,180,400,20,58,10); }
		if(GetX<cx){ PlaySE(SElaserm3); }
		}
		if(type==2){
			if(GetX<cx){ CreateShot01(GetX,GetY,2,0,123,0); CreateShot01(GetX,GetY,1,0,123,10);}
			if(GetX>cx){ CreateShot01(GetX,GetY,2,180,123,0); CreateShot01(GetX,GetY,1,180,123,10);}
		if(GetX<cx){ PlaySE(SEshotb6); }
		}
		if(type==3){
		let shot1=0;
		let delay=0;
		let angle=GetAngleToPlayer;
			loop(10){
			CreateShotA(shot1,GetX,GetY,10);
			SetShotDataA(shot1,0,3,angle,0,-0.1,0,44);
			SetShotDirectionType(PLAYER);
			SetShotDataA(shot1,40+delay,4,0,0,0,0,37);
			SetShotDirectionType(ABSOLUTE);
			FireShot(shot1);
			delay+=4;
			angle+=360/10;
			}
		if(GetX<cx){ PlaySE(SEshotm1); }
		}
		if(type==4){
		let speed=5;
		let color=1;
			loop(15){
			if(GetX<cx){ CreateShot01(GetX,GetY,speed,0,144+color,10); }
			if(GetX>cx){ CreateShot01(GetX,GetY,speed,180,144+color,10); }
			speed-=0.3;
			color++;
			if(color>10){ color=1; }
			}
		if(GetX<cx){ PlaySE(SEshotm3); }
		}
	}
type++;
if(type>4){ type=0; }
if(GetCommonDataDefault("SpellcardPhase",0)==1 && movetime2==28){ phase=1; }
movetime2=0;
move=0;
}


time++;
frame++;

}

@DrawLoop{
	SetGraphicScale(0.2,0.2);
	SetTexture(GRfamiliar);
	SetGraphicAngle(0,0,time*2);
	SetColor(255,255,255);
	SetRenderState(ADD);
	SetAlpha(100);
	SetGraphicRect(0,0,200,200);
	DrawGraphic(GetX,GetY);
}

@Finalize{
}

}